package exam.axhu.junit;

import static org.junit.Assert.*;

import java.util.List;

import exam.axhu.entity.Choice;
import exam.axhu.service.ChoiceService;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ChoiceTest {
	private static ChoiceService choiceService;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception{
		try {
			ApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
			choiceService =(ChoiceService) act.getBean("choiceServiceImpl");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void save() {
		if(choiceService.save(new Choice("我们","是","中国","人","民","B"))==1)
			System.out.println("already have!");
	
	}
	
	@Test
	public void delete() {
		choiceService.delete(1);
	
	}
	
	@Test
	public void update() {
		Choice choice = choiceService.findByID(22);
		choice.setChoiceB("not very good");
		choiceService.update(choice);
	
	}
	
	
	
	@Test
	public void find() {
		Choice ems = choiceService.findByID(11);
		/*if(ems==null) System.out.println("NO");
		else*/
			System.out.println(ems.getChoiceID());
	}
	
	
	@Test
	public void list() {
	
		List<Choice> ems = choiceService.list();
		for(Choice em:ems){
			System.out.println(em.getChoiceID());
		}
				
	}

}
